<?php
namespace app\back\controller;
use app\common\controller\AdminBase;
// use app\common\model\User;
use think\View;//视图
use think\Controller;//控制器
use think\Redirect;//重定向
use think\Session;//session
use think\Loader;//引入model
use think\Request;//请求
use think\File;//文件上传
use think\Url;//路由

class Score extends AdminBase {
    public function index() {
         $zid=session('ext_user.zid');
          $score=Loader::model('Order')->field('score,create_time')->where(array('zid'=>$zid))->select();     
          $sum=0;
          $jifen=0;
          $com=0;
          foreach ($score as $k => $v) {
               $startdate = strtotime(date('Ymd',$v['create_time']));
               $enddate = strtotime(date('Ymd',time()+86400));
               $i=(($enddate-$startdate)/86400)-1;
               $bili=pow((1-1/2000),$i);
               $score=$v['score']*$bili;
                $jifen=$jifen+$score;
               $jifen1=round($jifen,2);
               $sum=$sum+$v['score'];
               $money1=round($sum-$jifen1, 2);;
          }
         $commit=Loader::model('Commit')->field('money')->where(array('zid'=>$zid))->select();
           foreach ($commit as $k => $v1) {
            $com=$com+$v1['money'];
           }
         $money=$money1-$com;
          $this->assign('sum',$jifen1);
          $this->assign('money',$money);
        return $this->fetch('index');
    }



    public function info(){

     return $this->fetch();
    }

   public function sum(){
$zid=session('ext_user.zid');
    $request = Request::instance();
        if ($request->isPost()) {
            $params = $request->param();
            $starttime=strtotime($params['start_time']);
            $endtime=strtotime($params['end_time']);
            $ruleModel = Loader::model('Order');
          if(!empty($params['end_time'])&&!empty($params['start_time'])){
           $lists = $ruleModel->where(array('zid'=>$zid))->where('create_time','between time',[$starttime,$endtime])->paginate(5);
          }else{
            $ruleModel = Loader::model('Order');
            $lists = $ruleModel::where(array('zid'=>$zid))->paginate(5);
          } 
          } else{
            $ruleModel = Loader::model('Order');
            $lists = $ruleModel::where(array('zid'=>$zid))->paginate(5);
          
          } 
            $this->assign('lists', $lists);
            $this->assign('pages', $lists->render());
            // $ruleModel = Loader::model('User');
            // $ruleRows = $ruleModel::select();;
            // $this->assign('ruleRows', $ruleRows);
            return $this->fetch();

 
    }


}